/**
 * 命名=> api_xxx
 */
import { request } from "../request";
import { useUserStore } from "@/store/user";


// 上传图片资料
export const uploadFile = (path, waterName = "") => {
	return new Promise((resolve, reject) => {
		uni.showLoading({
			title: "正在上传...",
			mask: true,
		});
		uni.uploadFile({
			url: import.meta.env.VITE_APP_API_BASEURL + "/api/h5/anno/upload",
			filePath: path,
			name: "file",
			header: {
				"Authorization": uni.getStorageSync("token") || "",
			},
			formData: {
				waterName,
			},
			success: (res) => {
				let data = JSON.parse(res.data);
				resolve(data.data);
			},
			complete() {
				uni.hideLoading();
			},
		});
	});
};


// 获取系统设置详情
export const api_get_homeConfig = async (params = {}) => {
	return request({ url: `/home-config/tenant/${useUserStore().tenantId}`, method: "get", params: {} });
};

// 资讯分页
export const api_get_bulletinsPage = async (params = {}) => {
	return request({ url: `/bulletins/org/${useUserStore().tenantId}`, method: "get", params });
};

// 资讯-详情
export const api_get_bulletinsDetail = async (id) => {
	return request({ url: `/bulletins/${id}`, method: "get", params: {} });
};

// 活动分页
export const api_get_activityPage = async (params = {}) => {
	return request({ url: `/events/org/${useUserStore().tenantId}`, method: "get", params });
};

// 活动-详情
export const api_get_activityDetail = async (id) => {
	return request({ url: `/events/${id}`, method: "get", params: {} });
};

// 宗祠志
export const api_get_ancestralHall = async (params = {}) => {
	return request({ url: `/ancestral-hall-records/org/${useUserStore().tenantId}`, method: "get", params });
};

// 姓氏源流
export const api_get_surnNameOrigin = async (params = {}) => {
	return request({ url: `/surname-origin/org/${useUserStore().tenantId}`, method: "get", params });
};

// 家风家训
export const api_get_familyPrecepts = async (params = {}) => {
	return request({ url: `/family-precepts/org/${useUserStore().tenantId}`, method: "get", params });
};

// 名人堂-分页查询
export const api_get_hallOfFamePage = async (params = {}) => {
	return request({ url: `/hall-of-fame/org/${useUserStore().tenantId}/page`, method: "get", params });
};

// 名人堂-x详情
export const api_get_hallOfFameDetail = async (id) => {
	return request({ url: `/hall-of-fame/${id}`, method: "get", params: {} });
};

// 历史资料-分页查询
export const api_get_articlesPage = async (params = {}) => {
	return request({ url: `/articles/org/${useUserStore().tenantId}`, method: "get", params });
};

// 历史资料-详情
export const api_get_articlesDetail = async (id) => {
	return request({ url: `/articles/${id}`, method: "get", params: {} });
};

// 当代风范-分页查询
export const api_get_personOfFamePage = async (category, params = {}) => {
	return request({
		url: `/person-of-fame/org/${useUserStore().tenantId}/category/${category}`,
		method: "get",
		params
	});
};

// 当代风范-详情
export const api_get_personOfFameDetail = async (id) => {
	return request({ url: `/person-of-fame/${id}`, method: "get", params: {} });
};

// 宗亲理事
export const api_get_kinsman = async (params = {}) => {
	return request({ url: `/clan-organization-member/org/${useUserStore().tenantId}`, method: "get", params });
};

// 寻根服务-分页查询
export const api_get_rootSearchPage = async (params = {}) => {
	return request({ url: `/root-search/org/${useUserStore().tenantId}`, method: "get", params });
};

// 寻根服务-添加
export const api_post_rootSearch = async (params = {}) => {
	params.tenantId = useUserStore().tenantId
	return request({ url: `/root-search`, method: "post", data: params });
};


// 功德榜-分页查询-金额从大到小排序
export const api_get_meritsAmountPage = async (params = {}) => {
	return request({ url: `/merits/org/${useUserStore().tenantId}/amount/desc/page`, method: "get", params });
};

// 功德榜-分页查询-时间排序
export const api_get_meritsTimePage = async (params = {}) => {
	return request({ url: `/merits/org/${useUserStore().tenantId}/time/desc/page`, method: "get", params });
};

// 功德榜-捐赠
export const api_post_merits = async (params = {}) => {
	return request({ url: `/merits`, method: "post", data: params });
};

// 牌位阁-分页查询-号码排序
export const api_get_memorialNumberPage = async (params = {}) => {
	return request({
		url: `/memorial-tablet/org/${useUserStore().tenantId}/tablet-number/asc/page`,
		method: "get",
		params
	});
};

// 牌位阁-分页查询-时间排序
export const api_get_memorialTimePage = async (params = {}) => {
	return request({
		url: `/memorial-tablet/org/${useUserStore().tenantId}/publish-time/desc/page`,
		method: "get",
		params
	});
};

// 牌位阁-加牌位
export const api_post_memorial = async (params = {}) => {
	return request({ url: `/memorial-tablet`, method: "post", data: params });
};

// 上香
export const api_post_incenseOffering = async (params = {}) => {
	return request({ url: `/incense-offering`, method: "post", data: params });
};

// 上香-分页查询
export const api_get_incenseOfferingPage = async (params = {}) => {
	return request({
		url: `/incense-offering/org/${useUserStore().tenantId}/page`,
		method: "get",
		params
	});
};


// 获取支付参数
export const api_post_payParams = async (params = {}) => {
	return request({ url: `/wxpay/order-data`, method: "post", data: params });
};

// 创建支付订单
export const api_post_createPay = async (params = {}) => {
	return request({ url: `/wxpay/create`, method: "post", data: params });
};

// 查询支付状态
export const api_get_payStatus = async (params = {}) => {
	return request({ url: `/wxpay/callback`, method: "post", data: params });
};

// 根据姓名查询族谱列表
export const api_get_familyByName = async (params = {}) => {
	return request({ url: `/cp-family-members/search/name`, method: "get", params });
};

// 获取指定人员的 上下四代人员信息
export const api_get_familyWufu = async (id) => {
	return request({ url: `/cp-family-members/${id}/wufu-jiuzu-tree`, method: "get", params: {} });
};